define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

        var Controller = {
            index: function () {
                // 初始化表格参数配置
                Table.api.init({
                    extend: {
                        index_url: 'jy/service_order/index' + location.search,
                        add_url: '',
                        edit_url: 'jy/service_order/edit',
                        del_url: '',
                        multi_url: 'jy/service_order/multi',
                        import_url: 'jy/service_order/import',
                        table: 'service_order',
                    }
                });

                var table = $("#table");

                // 初始化表格
                table.bootstrapTable({
                    url: $.fn.bootstrapTable.defaults.extend.index_url,
                    pk: 'id',
                    sortName: 'update_time',
                    search: false,
                    undefinedText: '',
                    exportOptions: {
                        fileName: 'export_' + Moment().format("YYYY-MM-DD"),
                        ignoreColumn: ['operate'] //默认不导出第一列(checkbox)与操作(operate)列
                    },
                    columns: [
                        [
                            {field: 'id', title: __('Id')},
                            {field: 'user_id', title: __('User_id'), visible: false},
                            {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                            {field: 'service.service_name', title: __('Service_id'), operate: 'LIKE'},
                            {field: 'username', title: __('Username'), operate: 'LIKE'},
                            {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                            {field: 'city', title: __('City'), operate: 'LIKE'},
                            {field: 'address', title: __('Address'), visible: false, operate: false},
                            {field: 'remark', title: __('Remark'), operate: false},
                            {
                                field: 'status',
                                title: __('Status'),
                                searchList: {
                                    "0": __('Status 0'),
                                    "1": __('Status 1'),
                                    "2": __('Status 2'),
                                    "3": __('Status 3')
                                },
                                formatter: Controller.api.formatter.status
                            },
                            {field: 'create_user', title: __('Create_user'), operate: false, visible: false},
                            {
                                field: 'create_time',
                                title: __('Create_time'),
                                sortable: true,
                                autocomplete: false,
                                operate: false,
                            },
                            {field: 'update_user', title: __('Update_user'), operate: false, visible: false},
                            {
                                field: 'update_time',
                                title: __('Update_time'),
                                sortable: true,
                                autocomplete: false,
                                operate: false,
                            },
                            {
                                field: 'operate',
                                title: __('Operate'),
                                table: table,
                                events: Table.api.events.operate,
                                formatter: Table.api.formatter.operate
                            },
                        ]
                    ]
                });

                // 为表格绑定事件
                Table.api.bindevent(table);
            },
            add: function () {
                Controller.api.bindevent();
            },
            edit: function () {
                Controller.api.bindevent();
            },
            api: {
                bindevent: function () {
                    Form.api.bindevent($("form[role=form]"));
                },
                formatter: {
                    status: function (value, row, index) {
                        value = value === null ? '' : value.toString();
                        let status_text = row.status_text;
                        var colorArr = {'0': 'info', '1': 'warning', '2': 'success', '3': 'danger'};
                        //渲染Flag
                        var html = [];
                        html.push('<span class="label label-' + colorArr[value] + '" data-toggle="tooltip" title="' + status_text + '">' + status_text + '</span>');
                        return html.join(' ');
                    },
                }
            },
        }
        return Controller;
    }
);